package khs.java_resize.main.java;

import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args ) throws IOException
    {
        File source = new File("sample.jpg");
        BufferedImage sourceBufferedImage = ImageIO.read(source);
        int width = sourceBufferedImage.getWidth();
        int height = sourceBufferedImage.getHeight();
        
        BufferedImage destBufferedImage = new BufferedImage((int) (width*0.5), (int)(height*0.5), sourceBufferedImage.getType());
        AffineTransform affineTransform = new AffineTransform();
        affineTransform.scale(0.5, 0.5);
        AffineTransformOp affineTransformOp = new AffineTransformOp(affineTransform, AffineTransformOp.TYPE_BILINEAR);
        destBufferedImage = affineTransformOp.filter(sourceBufferedImage, destBufferedImage);
        
        File dest = new File("convert.png");
        ImageIO.write(destBufferedImage, "png", dest);
    }
}
